package com.yyyzzz.servlet;

import com.yyyzzz.DAO.impl.teacherDaoimpl;
import com.yyyzzz.bean.Teacher;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

public class teacherRegisterServlet extends HttpServlet {
    @Override
    protected void doGet (HttpServletRequest req , HttpServletResponse resp) throws ServletException, IOException {
        int id = Integer.parseInt (req.getParameter ("teacherNo"));
        String name = req.getParameter ("teachername");
        String pwd1 = req.getParameter ("Pwd1");
        String pwd2 = req.getParameter ("Pwd2");
        String job = req.getParameter ("teacherjob");
        String sex = req.getParameter ("sex");
        teacherDaoimpl teacherDaoimpl = new teacherDaoimpl ();
        Teacher teacher = new Teacher (id , name , pwd1 , job , sex);
        try {
            Teacher teacher1 = teacherDaoimpl.check (id);
            if ( teacher1 != null ) {
                resp.getWriter ().write ("该教师号已被注册，请重新输入！");
            } else if ( pwd2.equals (pwd1) ) {
                teacherDaoimpl.insterteacher (teacher);
                resp.getWriter ().write ("欢迎用户"+name+"注册成功!!!");
            }else {
                resp.getWriter ().write("两次输入密码不一致请重新输入！！！");
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace ();
        } catch (ClassNotFoundException e) {
            e.printStackTrace ();
        }
    }

    @Override
    protected void doPost (HttpServletRequest req , HttpServletResponse resp) throws ServletException, IOException {
        doGet (req , resp);
    }
}
